---
alert-message: ', <a href="http://getbootstrap.com" class="alert-link">http://getbootstrap.com</a>, and <a href="http://www.virtuosoft.eu/code/bootstrap-touchspin/">http://www.virtuosoft.eu/code/bootstrap-touchspin/</a>.'
categories: [Widgets]
layout: page
title: Bootstrap Touchspin
resource: true
url-js-extra: '//rawgit.com/istvan-ujjmeszaros/bootstrap-touchspin/3.1.1/dist/jquery.bootstrap-touchspin.min.js'
---
      <h2>Example with postfix</h2>
      <input id="demo1" type="text" value="55" name="demo1">
      <script>
        $("input[name='demo1']").TouchSpin({
          min: 0,
          max: 100,
          step: 0.1,
          decimals: 2,
          boostat: 5,
          maxboostedstep: 10,
          postfix: '%'
        });
      </script>
      <h2>With prefix</h2>
      <form class="form-horizontal" role="form">
        <div class="form-group">
          <label for="demo2" class="col-md-3 control-label">Example:</label>
          <div class="col-md-9">
            <input id="demo2" type="text" value="0" name="demo2" class="col-md-8 form-control">
          </div>
        </div>
      </form>
      <script>
        $("input[name='demo2']").TouchSpin({
          min: -1000000000,
          max: 1000000000,
          stepinterval: 50,
          maxboostedstep: 10000000,
          prefix: '$'
        });
      </script>
      <h2>Vertical button alignment</h2>
      <input id="demo_vertical" type="text" value="" name="demo_vertical">
      <script>
        $("input[name='demo_vertical']").TouchSpin({
          verticalbuttons: true
        });
      </script>
      <h2>Vertical buttons with custom icons</h2>
      <input id="demo_vertical2" type="text" value="" name="demo_vertical2">
      <script>
        $("input[name='demo_vertical2']").TouchSpin({
          verticalbuttons: true,
          verticalupclass: 'glyphicon glyphicon-plus',
          verticaldownclass: 'glyphicon glyphicon-minus'
        });
      </script>
      <h2>Init with empty value</h2>
      <input id="demo3" type="text" value="" name="demo3">
      <script>
        $("input[name='demo3']").TouchSpin();
      </script>
      <h2>Value attribute is not set <small>(applying settings.initval)</small></h2>
      <input id="demo3_21" type="text" value="" name="demo3_21">
      <script>
        $("input[name='demo3_21']").TouchSpin({
          initval: 40
        });
      </script>
      <h2>Value is set explicitly to 33 <small>(skipping settings.initval)</small></h2>
      <input id="demo3_22" type="text" value="33" name="demo3_22">
      <script>
        $("input[name='demo3_22']").TouchSpin({
          initval: 40
        });
      </script>
      <h2>Button postfix (small)</h2>
      <input id="demo4" type="text" value="" name="demo4" class="input-sm">
      <script>
        $("input[name='demo4']").TouchSpin({
          postfix: "a button",
          postfix_extraclass: "btn btn-default"
        });
      </script>
      <h2>Button postfix (large)</h2>
      <div class="input-group input-group-lg">
        <input id="demo4_2" type="text" value="" name="demo4_2" class="form-control input-lg">
      </div>
      <script>
        $("input[name='demo4_2']").TouchSpin({
          postfix: "a button",
          postfix_extraclass: "btn btn-default"
        });
      </script>
      <h2>Button group</h2>
      <div class="input-group">
        <input id="demo5" type="text" class="form-control" name="demo5" value="50">
        <div class="input-group-btn">
          <button type="button" class="btn btn-default">Action</button>
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu pull-right" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </div>
      </div>
      <script>
        $("input[name='demo5']").TouchSpin({
          prefix: "pre",
          postfix: "post"
        });
      </script>
      <h2>Change button class</h2>
      <input id="demo6" type="text" value="50" name="demo6">
      <script>
        $("input[name='demo6']").TouchSpin({
          buttondown_class: "btn btn-link",
          buttonup_class: "btn btn-link"
        });
      </script>
      <h2>Event demo</h2>
      <div class="row">
        <div class="col-md-3">
          <input id="demo7" type="text" value="50" name="demo7">
        </div>
        <div class="col-md-9">
          <pre id="demo7textarea" style="height:200px;overflow:auto;"></pre>
        </div>
        <script>
          var i = $("input[name='demo7']"),
            demoarea = $("#demo7textarea"),
            text = "";
          function writeLine(line) {
            text += line + "\n";
            demoarea.text(text);
            demoarea.scrollTop(
              demoarea[0].scrollHeight - demoarea.height()
            );
          }
          i.TouchSpin({});
          i.on("touchspin.on.startspin", function() {
            writeLine("touchspin.on.startspin");
          });
          i.on("touchspin.on.startupspin", function() {
            writeLine("touchspin.on.startupspin");
          });
          i.on("touchspin.on.startdownspin", function() {
            writeLine("touchspin.on.startdownspin");
          });
          i.on("touchspin.on.stopspin", function() {
            writeLine("touchspin.on.stopspin");
          });
          i.on("touchspin.on.stopupspin", function() {
            writeLine("touchspin.on.stopupspin");
          });
          i.on("touchspin.on.stopdownspin", function() {
            writeLine("touchspin.on.stopdownspin");
          });
          i.on("touchspin.on.min", function() {
            writeLine("touchspin.on.min");
          });
          i.on("touchspin.on.max", function() {
            writeLine("touchspin.on.max");
          });
        </script>
      </div>
